// 作业题2：泛型类实现多个接口并带约束
// 定义：
// 接口 Identifiable，包含 id: number
// 接口 Timestamped，包含 createdAt: Date
// 泛型类 Record<T>，要求 T 必须同时实现 Identifiable 和 Timestamped
// 类中包含方法 isRecent(): boolean，判断 createdAt 是否在最近7天内
// 测试用例：
// class User implements Identifiable, Timestamped {
//   id = 1;
//   createdAt = new Date();
// }
// const record = new Record<User>();
// console.log(record.isRecent()); // 输出: true
// 定义接口
interface Identifiable {
  id: number;
}

interface Timestamped {
  createdAt: Date;
}


class Record<T extends Identifiable & Timestamped> {
  private data: T;

  constructor(data: T) {
    this.data = data;
  }

  isRecent(): boolean {
    const sevenDaysAgo = Date.now() - 7 * 24 * 60 * 60 * 1000;
    return this.data.createdAt.getTime() >= sevenDaysAgo;
  }
}

class User implements Identifiable, Timestamped {
  id = 1;
  createdAt = new Date();
}
const record = new Record<User>(new User());
console.log(record.isRecent());

